﻿using FluentNHibernate.Mapping;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YYSite.Domain.System;
using YYSite.Domain.System.Permissions;

namespace YYSite.Repository.System.Permissions
{
   public class PermissionMap:ClassMap<Permission>
    {
        public PermissionMap()
        {
            this.Table("Permission");
            this.Schema(SystemConstant.Schema);

            this.Id(c=>c.Id);
            this.Map(c => c.ParentId).Nullable();
            this.Map(c => c.Name).Not.Nullable().Length(128).Unique();
            this.Map(c => c.DisplayName).Not.Nullable().Length(128);
            this.Map(c => c.Description).Not.Nullable().Length(128);
            this.Map(c => c.Area).Nullable().Length(128);
            this.Map(c => c.Controller).Nullable().Length(128);
            this.Map(c => c.Action).Nullable().Length(128);
            this.Map(c => c.Url).Nullable().Length(256);
            this.Map(c => c.Type);
            this.Map(c => c.Icon).Not.Nullable().Length(128);
            this.Map(c => c.Sequence);
            this.Map(c => c.CreateTime).Not.Nullable().Default("GETDATE()");

            this.HasMany<Permission>(u => u.Permissions).AsSet().KeyColumn("ParentId").Cascade.All();
            this.References<Permission>(o => o.ParentPermission).Not.LazyLoad().Column("ParentId");
        }
    }
}
